import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

<#-- ----------  BEGIN 字段循环遍历 构造表格列  ---------->
<#assign component=["Select", 'RadioGroup', "RadioButtonGroup", "CheckboxGroup","TreeSelect"]>
<#assign ApiComponent=["ApiTreeSelect","ApiSelect"]>
<#assign dictTypes=["api", 'custom']>
export const columns: BasicColumn[] = [
<#list customTableInfo.tableFieldConfig as field>
<#if field.isGenColumn>
  {
    title: <#if field.comment!?length gt 0>'${field.comment}'<#else>'${field.propertyName}'</#if>,
    dataIndex: '${field.propertyName}',
    <#if !field.showTableColumn>defaultHidden: true,</#if>
    <#if dictTypes?seq_contains("${field.dictType}") && component?seq_contains("${field.componentType}")>
        customRender:({ record }) =>{
        const options = [
        <#list field.fieldDict as option>
            {
                label: ${option.label},
                value: ${option.value},
            },
        </#list>
        ];
        return options.find((op) => op.value === record.${field.propertyName}).label;
        },
    </#if>
    align: 'center',
    width: 200,
  },
</#if>
</#list>
];

<#-- ----------  end 字段循环遍历 构造表格列  ---------->

<#-- ----------  BEGIN 字段循环遍历 构造搜索表单  ---------->
export const searchFormSchema: FormSchema[] = [
<#list  customTableInfo.tableFieldConfig as field>
<#if field.isQuery>
  {
    field: '${field.propertyName}',
    label: <#if field.comment!?length gt 0>'${field.comment}'<#else>'${field.propertyName}'</#if>,
    component: '${field.componentType}',
    componentProps: {
        placeholder: <#if !component?seq_contains("${field.componentType}")>'请输入<#else>'请选择</#if><#if field.comment!?length gt 0>${field.comment}'<#else>${field.propertyName}'</#if>,
        <#if dictTypes?seq_contains("${field.dictType}") && component?seq_contains("${field.componentType}")>
        options:[
        <#list field.fieldDict as option>
            {
                label: ${option.label},
                value: ${option.value},
            },
        </#list>
        ];
        </#if>
    },
    colProps: { span: 6 },
  },
</#if>
</#list>
];

<#-- ----------  END 字段循环遍历 构造搜索表单  ---------->

<#-- ----------  BEGIN 字段循环遍历 新增编辑表单  ---------->
export const formSchema: FormSchema[] = [
<#list  customTableInfo.tableFieldConfig as field>
<#if field.isGenFieldByUpdateOrCreate>
  {
    field: '${field.propertyName}',
    label: <#if field.comment!?length gt 0>'${field.comment}'<#else>'${field.propertyName}'</#if>,
    component: '${field.componentType}',
    show: ${field.isShowFieldByUpdateOrCreate?string('true', 'false')},
    required: ${field.required?string('true', 'false')},
    <#if field.checkRule!?length gt 0>
    rules:[
        {
            validator: (rule, value, callback: (error?: string) => void) => {
                const reg = /${field.checkRule}/;
                if (!reg.test(value)) {
                    callback('请输入正确的<#if field.comment!?length gt 0>${field.comment}<#else>${field.propertyName}</#if>格式');
                    return;
                }
                callback();
            },
        }
    ],</#if>
    componentProps: {
        disabled: ${field.isDisableField?string('true', 'false')},
        placeholder: <#if !component?seq_contains("${field.componentType}")>'请输入<#else>'请选择</#if><#if field.comment!?length gt 0>${field.comment}'<#else>${field.propertyName}'</#if>,
        <#if dictTypes?seq_contains("${field.dictType}") && component?seq_contains("${field.componentType}")>
            options:[
            <#list field.fieldDict as option>
                {
                    label: ${option.label},
                    value: ${option.value},
                },
            </#list>
            ];
        </#if>
    },
    colProps: { span: 6 },
 },
</#if>
</#list>
];
<#-- ----------  END 字段循环遍历 新增编辑表单  ---------->
